﻿using System;
using System.ComponentModel;

namespace DBProject
{
    public class PersonDBEntry : INotifyPropertyChanged
    {
        #region Fields

        private string firstName;
        private string lastName;
        private UInt16 age;
        private string email;
        private UInt32 phonenumber;

        #endregion Fields

        #region Getters/setters

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; onPropertyChanged(this, "First name"); }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; onPropertyChanged(this, "Last name"); }
        }

        public UInt16 Age
        {
            get { return age; }
            set { age = value; onPropertyChanged(this, "Age"); }
        }

        public string Email
        {
            get { return email; }
            set { email = value; onPropertyChanged(this, "E-mail"); }
        }

        public UInt32 PhoneNumber
        {
            get { return phonenumber; }
            set { phonenumber = value; onPropertyChanged(this, "Phone number"); }
        }

        public string Details
        {
            get
            {
                return string.Format("First name:\t{0}\nLast name:\t{1}\nAge:\t\t{2}\nE-mail:\t\t{3}\nPhone number:\t{4}", this.firstName, this.lastName, Convert.ToUInt16(this.age), this.email, Convert.ToUInt32(this.phonenumber));
            }
        }

        #endregion Getters/setters

        #region Methods

        public string WriteFileEntry
        {
            get
            {
                return (String.Format("{0};{1};{2};{3};{4}", firstName, lastName, age, email, phonenumber));
            }
        }

        #endregion Methods

        // Declare the PropertyChanged event
        public event PropertyChangedEventHandler PropertyChanged;

        // OnPropertyChanged will raise the PropertyChanged event passing the
        // source property that is being updated.
        private void onPropertyChanged(object sender, string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}